package com.spring.boot.demo.controller;

import com.spring.boot.demo.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityService cityService;

    /**
     * http://localhost:8081/city/add
     * @return
     */
    @GetMapping(value = "/add")
    public String add(){
        cityService.insertCity();
        return "ok";
    }

    /**
     * http://localhost:8081/city/sleep
     * @return
     */
    @GetMapping(value = "/sleep")
    public String sleep(){
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "ok";
    }

    @GetMapping(value = "/hi")
    public Map<String, Object> hi(@RequestParam String name){
        Map<String, Object> map = new HashMap<>();

        cityService.insertCity();
        map.put("name", name);
        return map;
    }

}
